package view.completeView.entityView;

import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;

import reference.constants.ConstantProgram;
import utilities.view.PanelBuffer;
import view.completeView.CompletePanel;

import controller.entitiesManagement.Entity;

public class EntityView extends Component implements EntityListener {

	private static final long serialVersionUID = 5397861681089596178L;
	private CompletePanel m_panel;
	private int m_posX;
	private int m_posY;
	private Color m_color;
	
	public EntityView(CompletePanel panel, Entity entity){
		m_panel = panel;
		m_posX = entity.getPosX();
		m_posY = entity.getPosY();
		m_color = entity.getDefaultColor();
		entity.addEntityListener(this);
	}
	
	public void changeState(int new_state) {
		switch(new_state){
			default:
				m_color = Color.BLACK;
		}
		m_panel.repaint();
	}

	public void move(int new_pos_x, int new_pos_y) {
		m_posX = new_pos_x;
		m_posY = new_pos_y;		
		m_panel.repaint();
	}
	
	public void paint(PanelBuffer buffer){
		Graphics graphics = buffer.createGraphics();
		graphics.setColor(m_color);
		graphics.fillOval(m_posX, m_posY, ConstantProgram.ENTITY_WIDTH, ConstantProgram.ENTITY_WIDTH);
	}

}
